<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Forum/classes/PhpFox_ComponentEditPost.class.php, $Author:  $ */



/** Edit post (edit reply) component
 * 
 * 1. oCurrUser (optional) current user object; if null or omitted - used current user
 * 
 * @package module.forum
 * @version $Id: PhpFox_ComponentEditPost.class.php 280 2008-02-04 17:52:29Z phpfoxsv $
 *   
 */
class PhpFox_Mod_Forum_ComponentEditPost extends BaseComponent
{

    /** Processing method
     */
	function process()
	{
        $oSrvSec = &App::getModuleService('Account', 'Security');
        /* @var $oSrvSec PhpFox_Mod_Account_ServiceSecurity */
        $oSrvSec->checkPerm('forum', 'full');
        	    
	    $oReq = &App::getRequest();
	    /* @var $oReq Request */
	    
	    $oTxt = App::newObject('Text');
	    
	    $oUser = $this->getParam('oUser', null);
	    if (!$oUser)
	    {
	        $oSrvSec = &App::getModuleService('Account', 'Security');
	        /* @var $oSrvSec PhpFox_Mod_Account_ServiceSecurity */
	        $oUser = $oSrvSec->getCurrentUser();
	    }
	    
        $oPost = $this->_oModule->getItem('ForumReply');
        $oPost->load($oReq->getInt('editpost'));
        
        if ( !App::isStaff() && ($oPost->aData['user'] != App::getUser('user')) )
		{
        	App::gotoUrl('public.forum');
		}
			
	    switch($oReq->getAction())
        {
            case 'forum_edit_post':
                if ($oUser)
                {
                    $oTxt = App::newObject('Text');
                    $sText  = $oReq->get('text');
                    if ( '' != trim(strip_tags($sText)) )
					{
                    $oSrvForum = &$this->_oModule->getService('Forum');
                    /* @var $oSrvForum PhpFox_Mod_Forum_ServiceForum */
                    $oPost = $this->_oModule->getItem('ForumReply');
                    if ($oPost->load($oReq->getInt('editpost')))
                    {
                        $oPost->aData['text'] = $oTxt->preParseText($oTxt->parseText($oReq->get('text'),0,0,1));
                        $oPost->update(array('text'));
                        $oUrl = App::getUrl();
                        $oUrl->clearParams('editpost');
                        App::forward($oUrl->getUrl());
                    }
                    
					}else{
                        	$this->addErrors(App::format('validator.rule.req',	array(App::format('Mod_Forum.forum_message'), App::format('Mod_Forum.forum_message')) ));
                    }
                }
                break;
        }
        
		$oTpl = &$this->_oModule->getTemplate();

		$oTpl->assign(array(
            'sText' => $oPost->aData['text'],
            'aErrors'     => $this->getErrors(),
		));
		$srcHtml = $oTpl->fetch('EditPost.html');
		return $srcHtml;
	}

}
?>